package at.fhv.androideightpuzzle.network.message;

import java.util.ArrayList;
import java.util.List;

public class MessageQueue {
	
	private List<IMessage> m_queue;
	
	public MessageQueue(){
		m_queue=new ArrayList<IMessage>();
	}
	
	public synchronized void enqueue(IMessage message){
		if(message!=null){
			android.util.Log.d("MessageQueue", "enqueue");
			m_queue.add(message);
			
			notifyAll();
		}
	}
	
	public synchronized IMessage dequeue() throws InterruptedException{
		android.util.Log.d("MessageQueue", "dequeue.wait");
		while(m_queue.isEmpty()){
			wait();
		}
		android.util.Log.d("MessageQueue", "dequeue.ok");
		return m_queue.remove(0);
	}
}
